<!DOCTYPE html>
<html>
<head>
    <%include("/back/_include/meta.html",{"title":""}){}%>
    <%include("/back/_include/style.html"){}%>
    <link href="/assets/ui/h+/css/plugins/iCheck/custom.css" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <div class="row">
                        <div class="col-sm-12">
                            <form role="form" id="form">
                                <div class="form-group col-sm-6">
                                    <label>起始ip</label>
                                    <input type="text" id="ip" name="ip" value="${loginIp.ip!}" class="form-control" required="">
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> ip需合法</span>
                                </div>
                                <div class="form-group col-sm-6">
                                    <label>截止ip</label>
                                    <input type="text" id="ip2" name="ip2" value="${loginIp.ip2!}" class="form-control">
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> ip需合法,可为空</span>
                                </div>
                                <div class="form-group col-sm-8">
                                    <select class="form-control" id="black">
                                        <option value="">==黑名单/白名单==</option>
                                        <option value="true" <%if(loginIp.black){%>selected<%}%>>黑名单</option>
                                        <option value="false" <%if(!loginIp.black){%>selected<%}%>>白名单</option>
                                    </select>
                                </div>
                                <div class="form-group col-sm-6">
                                    <label>
                                        <input type="checkbox" id="open"  <%if(loginIp.open){%>checked<%}%> class="i-checks">
                                        开启
                                    </label>
                                </div>
                                <div>
                                    <button class="btn btn-lg btn-primary pull-left" id="save">
                                        <strong>保存</strong>
                                    </button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<%include("/back/_include/script.html"){}%>
<script src="/assets/ui/h+/js/plugins/validate/jquery.validate.min.js"></script>
<script src="/assets/ui/h+/js/plugins/validate/messages_zh.min.js"></script>
<script src="/assets/ui/h+/js/plugins/iCheck/icheck.min.js"></script>
<script>
    $.validator.setDefaults({
        submitHandler: function() {
            var ip = $$('#ip')
            var ip2 = $$('#ip2')
            if(!isValidIP(ip)){
                error("起始ip不合法")
                return
            }
            if(!isEmpty(ip2)&&!isValidIP(ip2)){
                error("截止ip不合法")
                return
            }
            var black = $('#black option:selected').val()
            console.log(black)
            if(isEmpty(black)){
                error("请选择黑/白名单")
                return
            }
            var open = $('#open').prop("checked")
            post("/b/loginIp/update",{"loginIp.id":"${loginIp.id!}","loginIp.admin_id":"${loginIp.admin_id!}","loginIp.ip":ip,"loginIp.ip2":ip2,"loginIp.black":black,"loginIp.open":open},function (res) {
                if(!res.success){
                    error(res.msg)
                    return;
                }
                success("更新成功",false,function () {
                    window.location.reload();
                })
            },function () {
                systemErr();
            })
        }
    });
    $(function () {
        $(".i-checks").iCheck({checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green",})
        $("#form").validate({
            messages: {
                ip: {required:"请输入起始ip"},
            }
        })
    });
</script>
</body>
</html>